<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.2.1/axios.js"></script>
</head>

<body>
    <ul class="list">
        <li></li>
    </ul>
    <button>获取电影</button>
    <button>添加电影</button>
    <button>修改电影</button>
    <button>局部修改</button>
    <button>删除电影</button>
    <script>
        // 获取ul和按钮
        let ul = document.querySelector('ul');
        let btns = document.querySelectorAll('button');
        // 获取数据 - 默认请求方式 - get
        axios('http://www.zhibao.com/movies').then(({data})=>{
            // console.log(data);
            ul.innerHTML = data.map(item=>`<li>${item.name}</li>`).join('');
        })
        // 添加数据
        btns[1].onclick = function(){
            axios('http://www.zhibao.com/movies',{
                method:'post',
                data:{
                    name:"满江红",
                    director:"张艺谋",
                    star:"易烊千玺"
                }
            }).then(val=>{
                console.log(val);
            })
        }
        // 修改数据
        btns[2].onclick = function(){
            axios('http://www.zhibao.com/movies/4',{
                method:"put",
                data:{
                    name:"相爱相杀",
                    director:"王阳",
                    star:"肖江瑶"
                }
            }).then(val=>{
                console.log(val);
            })
        }
        // 局部修改
        btns[3].onclick = function(){
            axios('http://www.zhibao.com/movies/4',{
                method:"patch",
                data:{
                    name:"终成眷属",
                   
                }
            }).then(val=>{
                console.log(val);
            })
        }
    
        // 删除数据
        btns[4].onclick = function(){
            axios('http://www.zhibao.com/movies/4',{
                method:'delete'
            }).then(val=>{console.log(val);})
        }
    </script>
</body>

</html>